xl: add 'xstrdup' next to 'xrealloc'
authorDavid Scott <dave.scott@citrix.com>
Thu, 9 Oct 2014 09:17:28 +0000 (10:17 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Mon, 20 Oct 2014 12:51:28 +0000 (13:51 +0100)
Signed-off-by: David Scott <dave.scott@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
tools/libxl/xl_cmdimpl.c

index 988ee28f7a1a88c4704740eef155228b6dccebb3..abe9ac63f13a839c211702bb83ed09f8c120afa9 100644 (file)
@@ -300,6 +300,19 @@ static void *xrealloc(void *ptr, size_t sz) {
     return r;
 }
 
+static char *xstrdup(const char *x) __attribute__ ((unused));
+static char *xstrdup(const char *x)
+{
+    char *r;
+    r = strdup(x);
+    if (!r) {
+        fprintf(stderr, "xl: Unable to strdup a string of length %zu.\n",
+                strlen(x));
+        exit(-ERROR_FAIL);
+    }
+    return r;
+}
+
 #define ARRAY_EXTEND_INIT(array,count,initfn)                           \
     ({                                                                  \
         typeof((count)) array_extend_old_count = (count);               \